package com.tucc.hello.other;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.other
 * @date 2021/5/25
 **/
public class SingleNums {

    public static void main(String[] args) {
        int[] other2 = {2,3,3,2,5,6,5};
        System.out.println(singleNumWhenOther2(other2));

        int[] other3 = {2,4,3,3,3,2,2};
        System.out.println(singleNumWhenOther3(other3));

    }

    public static int singleNumWhenOther2(int[] nums){
        int left = nums[0];
        for(int i = 1;i < nums.length;i ++){
            left ^= nums[i];
        }
        return left;
    }

    public static int singleNumWhenOther3(int[] nums){
        int one = 0, two = 0;
        for(int i = 0;i < nums.length;i ++){
            one = (one ^ nums[i]) & ~ two;
            two = (two ^ nums[i]) & ~ one;
        }
        return one;
    }
}
